//
//  main.m
//  Url
//
//  Created by mac on 16-5-22.
//  Copyright (c) 2016年 zz. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSString *baseURL = @"http://127.0.0.1:3000/";
        //        NSDictionary *params = @{
        //                                 @"wd":@"help",
        //                                 };
        //        NSMutableArray *arr = [NSMutableArray new];
        //        __block int i = 0;
        //        [params enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
        //            NSString *str = [NSString stringWithFormat:@"%@=%@",key, obj];
        //            [arr addObject:str];
        //            i += 1;
        //        }];
        //
        //        NSString *res = [arr componentsJoinedByString:@"&"];
        //        res = [res stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        //        res = [NSString stringWithFormat:@"%@?%@", baseURL, res];
        //        NSLog(@"%@",res);
        
        NSURL *url = [NSURL URLWithString:baseURL];
        NSURLRequest *req = [NSURLRequest requestWithURL:url];
        NSError *err;
        NSHTTPURLResponse *response;
        NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
        if (err) {
            NSLog(@"%@",err);
        }
        NSLog(@"status:%d",response.statusCode);
        NSLog(@"%@",response.allHeaderFields);
        NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"size:%lu", data.length);
        NSLog(@"%@",str);
    }
    return 0;
}

